
#include "TFGame.h"

TFGame::TFGame()
{
	_controller = NULL;
	_view = NULL;
	_model = NULL;
	_ai = NULL;
	_ruleChecker = NULL;
}

TFGame::~TFGame()
{
	_controller = NULL;
	_view = NULL;
	_model = NULL;
	_ai = NULL;
	_ruleChecker = NULL;
}

HRESULT TFGame::Initialize()
{
	HRESULT HR = E_FAIL;
		
	PA_Init();    // Initializes PA_Lib
	PA_InitVBL(); // Initializes a standard VBL

    PA_InitText(0,0);
	PA_InitSound();
    
    isRumbleInserted();
	
	PA_SetBgColor(0, PA_RGB(31, 31, 31));
    PA_SetTextCol(0,0,0,0);
	//Get MVC+AI+Rule Checker
	HR = TFInterfaceFactory::CreateTFController(_controller);
	RETURN_ON_ERROR(HR);

	HR = TFInterfaceFactory::CreateTFView(_view);
	RETURN_ON_ERROR(HR);

	HR = TFInterfaceFactory::CreateTFModel(_model);
	RETURN_ON_ERROR(HR);

	HR = TFInterfaceFactory::CreateTFAI(_ai);
	RETURN_ON_ERROR(HR);

	HR = TFInterfaceFactory::CreateTFRuleChecker(_ruleChecker);
	RETURN_ON_ERROR(HR);

	//give model access to view, controller, ai, and rule checker
	_model->SetRuleChecker(_ruleChecker);
	_view->SetModel(_model);
    _view->SetRuleChecker(_ruleChecker);
	_controller->SetModel(_model);
	_controller->SetView(_view);
	_controller->SetAI(_ai);
	_ai->SetModel(_model);
	_ai->SetRuleChecker(_ruleChecker);
	

	return HR;
}


HRESULT TFGame::SplashIntro()
{
	return _controller->DoSplashIntro();
}


HRESULT TFGame::RunGame()
{
	return _controller->ListenAndProcess();
}

HRESULT TFGame::ShutdownGame()
{
	return E_FAIL;
}
